﻿using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;

namespace PMAF.K3Cloud.SCM.Bill.BusinessPlugIn
{
    [HotUpdate]
    [Description("采购入库单更新批号")]
    public class InStock : AbstractBillPlugIn
    {
        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);

            //2025年2月28日停掉该功能
            //DateTime date = Convert.ToDateTime(View.Model.GetValue("FDate"));
            ////判断日期如果是当月最后一天，则生成前一天的日期
            //object billId = View.Model.GetPKValue();
            //if(billId == null )
            //{
            //    if (date.AddDays(1).Month > date.Month)
            //    {
            //        View.Model.SetValue("FDate", date.AddDays(-1));
            //    }
            //}
        }
        public override void EntryBarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            DynamicObject dataObject = View.Model.DataObject;
            if (e.BarItemKey.EqualsIgnoreCase("PMAF_GenerateLotBtn"))
            {
                if(dataObject != null)
                {
                    DynamicObjectCollection inStockEntries = dataObject["InStockEntry"] as DynamicObjectCollection;
                    int i = 0;
                    foreach(DynamicObject inStockEntry in inStockEntries)
                    {
                        DynamicObject purchaseSn = (DynamicObject)inStockEntry["F_PMAF_PurchaseSnId"];
                        string purchaseSnNo = purchaseSn["Number"].ToString();
                        View.Model.SetValue("FLot", purchaseSnNo, i);
                        i++;
                    }
                }
            }
        }
    }
}
